"""
学习进度模型
"""
from sqlalchemy import Column, Integer, Numeric, Enum, ForeignKey, DateTime, func
from sqlalchemy.orm import relationship
from .base import Base


class StudentProgress(Base):
    """学员学习进度表"""
    __tablename__ = "student_progress"
    
    student_id = Column(Integer, ForeignKey("students.id"), nullable=False, comment="学员ID")
    course_id = Column(Integer, ForeignKey("courses.id"), nullable=False, comment="课程ID")
    stage_number = Column(Integer, nullable=False, comment="当前阶段")
    progress_percentage = Column(Numeric(5, 2), default=0.00, comment="进度百分比")
    start_date = Column(DateTime, comment="阶段开始日期")
    end_date = Column(DateTime, comment="阶段结束日期")
    status = Column(Enum("not_started", "in_progress", "completed", "failed", name="progress_status"), 
                   default="not_started", comment="状态")
    
    # 关系
    student = relationship("Student", back_populates="student_progress")
    course = relationship("Course", back_populates="student_progress")
    
    def __repr__(self):
        return f"<StudentProgress(id={self.id}, student_id={self.student_id}, stage_number={self.stage_number})>"
